<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="header.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%-- <a href="${pageContext.request.contextPath}/user_insert.jsp" class="btn btn-primary">添加</a> --%>
	<a href="${path}/user?method=getUserInsertPage" class="btn btn-primary">添加</a>
	<a href="${path}/user_insert2.jsp" class="btn btn-primary">添加通过Ajax</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>密码</td>
			<td>邮箱</td>
			<td>年龄</td>
			<td>部门ID</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageInfo.list}" var="user">
			<tr>
				<td>${user.id}</td>
				<td>${user.name}</td>
				<td>${user.password}</td>
				<td>${user.email}</td>
				<td>${user.age}</td>
				<td>${user.departmentId}</td>
				<td><a href="javascript:deleteById(${user.id})">删除</a></td>
				<td><a href="${path}/user?method=getUserUpdatePage&id=${user.id}">修改</a></td>
			</tr>
		</c:forEach>
	</table>
	
	<nav aria-label="Page navigation">
		  <ul class="pagination">
		    <li>
		      <a href="#" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
		    <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
			    <li><a href="${path}/user?method=selectByPage&pageNo=${i}">${i}</a></li>
		    </c:forEach>
		   
		    <li>
		      <a href="#" aria-label="Next">
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
		  </ul>
		</nav>
	<script type="text/javascript">
		function deleteById(id) {
			/* 
			var isDelete = confirm('您确认要删除么？');
			if (isDelete) {
				location.href = '${pageContext.request.contextPath}/user?method=deleteById&id=' + id;
			} 
			*/
			
			// mylayer.confirm('您确认要删除么？', '${path}/user?method=deleteById&id=' + id);
			
			layer.confirm(
					'您确认要删除么？',
					{icon : 3},
					function(index){//点击确认触发
						$.post('${path}/user?method=deleteById',
								{'id' : id},
								function(jsonResult) {
									console.log(jsonResult);
									// {code: 0, data: null, msg: "删除成功", ok: true}
									if(jsonResult.ok) {
										mylayer.okUrl(jsonResult.msg, '${path}/user?method=selectByPage');
									} else {
										mylayer.errorMsg(jsonResult.msg);
									}
								},
								'json');
					}
				);
			
		}
	</script>
	
	
</body>
</html>